package Intercepting;

import java.util.ArrayList;
import java.util.List;

/**
 * @author CJJ
 * 创建缓存Cache
 */
public class Cache {
    private List<Service> services;

    public Cache(){
        services= new ArrayList<>();
    }

    public Service getService(String serviceName){
        Service service = services.stream().filter(s -> s.getName().equalsIgnoreCase(serviceName)).findFirst().orElse(null);
        if(service != null){
            return service;
        }
        return null;
    }

    public void addService(Service service){
        boolean exists =false;
        for (Service s : services){
            if(s.getName().equalsIgnoreCase(service.getName())){
                exists=true;
            }
        }
        if(!exists){
            services.add(service);
        }
    }
}
